package com.example.cloud.controller.business.medical;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.business.medical.TreatPlanHome;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.service.business.medical.TreatPlanHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Created by wangtao on 2018/7/2.
 */
@RestController
@RequestMapping("/treat/plan/home")
public class TreatPlanHomeController extends BaseController {

    @Autowired
    private TreatPlanHomeService treatPlanHomeService;

    @PostMapping("/search")
    public Result search(@RequestBody QueryModel model) {
        return this.singleQuery(model, TreatPlanHome.class);
    }

    @PostMapping("/saveOrUpdate/{patientId}")
    public void saveOrUpdate(@RequestBody List<TreatPlanHome> records, @PathVariable Long patientId) {
        treatPlanHomeService.batchInsert(records, patientId);
    }

    /**
     * 冻结
     */
    @PostMapping("/freeze/{id}")
    public Result freeze(@PathVariable Long id){
        return treatPlanHomeService.doFreeze(id);
    }

    /**
     * 激活
     */
    @PostMapping("/active/{id}")
    public Result active(@PathVariable Long id){
        return treatPlanHomeService.doActive(id);
    }

    /**
     * 单个删除
     * @param id
     * @return
     */
    @PostMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        return treatPlanHomeService.doDeleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     */
    @PostMapping("/delete")
    public void delete(@RequestBody List<Long> ids){
        treatPlanHomeService.doDelete(ids);
    }

    @PostMapping("/modify")
    public void modify(@RequestBody Map map){
        Long id = Long.valueOf(map.get("id").toString());
        BigDecimal price = new BigDecimal(map.get("totalPrice").toString());
        treatPlanHomeService.doModify(id, price);
    }
}
